﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using RapidWebDev.Platform.Initialization;
using RapidWebDev.Platform;
using System.Web;
using System.Configuration;

namespace RapidWebDev.SearchIndex.Tests
{
    public class MockAnotherApplicationInstaller : IInstaller
    {
        private IApplicationApi applicationApi;
        private ApplicationObject applicationObjectTemplate;

        public MockAnotherApplicationInstaller(IApplicationApi applicationApi)
        {
            this.applicationApi = applicationApi;
            this.applicationObjectTemplate = new ApplicationObject();
        }
        public MockAnotherApplicationInstaller(IApplicationApi applicationApi, ApplicationObject applicationObjectTemplate)
        {
            this.applicationApi = applicationApi;
            this.applicationObjectTemplate = applicationObjectTemplate;
        }
        #region IInstaller Members

        public void Install(string applicationName)
        {
            if (this.applicationApi.Exists(applicationName)) return;

            ApplicationObject applicationObject = this.applicationObjectTemplate;
            applicationObject.Id = Guid.Empty;
            applicationObject.Name = applicationName;

            string requestUri = HttpContext.Current != null ? HttpContext.Current.Request.Url.ToString() : "Local";
            applicationObject.Description = string.Format(@"Auto initialization on URI ""{0}"" at {1}", requestUri, DateTime.UtcNow);
            applicationObject["Theme"] = "Gray";
            applicationObject["IndexQueueDbConnectionName"] = "Idx2";
            this.applicationApi.Save(applicationObject);
        }

        public void Uninstall(string applicationName)
        {
            throw new NotImplementedException();
        }

        #endregion
    }
}
